package com.sl.biz.modular.workflow.dao.service.impl;

import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sl.biz.modular.workflow.dao.domain.entity.WorkflowTaskDO;
import com.sl.biz.modular.workflow.dao.mapper.WorkflowTaskMapper;
import com.sl.biz.modular.workflow.dao.service.WorkflowTaskDaoService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class WorkflowTaskDaoServiceImpl extends ServiceImpl<WorkflowTaskMapper, WorkflowTaskDO> implements WorkflowTaskDaoService {


    @InterceptorIgnore(tenantLine = "true")
    @Override
    public WorkflowTaskDO getByInstanceIdAndTaskCode(String instanceId, String taskCode) {
        LambdaUpdateWrapper<WorkflowTaskDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        lambdaUpdateWrapper.eq(WorkflowTaskDO::getWorkflowInstanceId, instanceId);
        lambdaUpdateWrapper.eq(WorkflowTaskDO::getTaskCode, taskCode);
        return super.getOne(lambdaUpdateWrapper);
    }

    @InterceptorIgnore(tenantLine = "true")
    @Override
    public Boolean updateStatusById(String id, String status) {
        LambdaUpdateWrapper<WorkflowTaskDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        lambdaUpdateWrapper.eq(WorkflowTaskDO::getId, id);
        lambdaUpdateWrapper.set(WorkflowTaskDO::getStatus, status);
        return super.update(lambdaUpdateWrapper);
    }
}
